<template>
	<view class="goods-item flex-row" @click="onClick(item)">
		<view class="goods-img-view">
			<image :src="item.img" mode="aspectFill" class="goods-img"></image>

			<image :src="$getImgUrl(`home/${index + 1}.png`)" mode="widthFix" class="img-sign" v-if="index < 3"></image>
		</view>

		<view class="right-info flex-col">
			<view class="goods-title ellipsis">{{ item.name }}</view>
			<view class="goods-sign-view flex-row-center" style="padding: 15rpx 0;">
				<view class="goods-sign-item">正品保障</view>
				<view class="goods-sign-item sign-chaoshi">超时赔付</view>
			</view>

			<view class="goods-desc">{{ item.desc }}</view>
			<view class="price-view flex-row-between">
				<view class="price-text flex-row-center">
					￥
					<text class="nowprice">{{ item.price }}</text>
				</view>
				<text class="buy-num">{{ item.buynum }}人已购买</text>
			</view>
			<!-- 			<view class="progress-view">
				<view class="active-progress">保底必中</view>
				<view class="progress-text">{{ item.minprice }}-{{ item.maxprice }}元</view>
				<image src="../../../static/images/home/100.png" mode="widthFix" class="circle-num"></image>
			</view> -->
			<view class="goods-info-list">
				<scroll-view scroll-x="true" class="scroll-x-view">
					<view class="goods-info-item" v-for="(cell, i) in item.list" :key="i"><image :src="cell.img" mode="aspectFill"></image></view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	name: 'GoodsItem',
	props: {
		item: {
			default: {},
			type: Object
		},
		index: {
			default: 0,
			type: Number
		}
	},
	data() {
		return {
			time: {},
			showCount: false
		};
	},
	mounted() {
		this.countDown();
	},
	methods: {
		onAddCart() {
			this.$emit('onAddCart');
		},
		onClick() {
			this.$emit('onClick');
		},
		timeFormat(param) {
			return param < 10 ? '0' + param : param;
		},
		countDown() {
			var interval = setInterval(() => {
				// 当前时间
				let nowTime = Date.parse(new Date()) / 1000;
				let endTime = Number(this.item.endtime);

				if (endTime == 0) {
					clearInterval(interval);
					return;
				}
				if (endTime - nowTime <= 0) {
					this.showCount = false;
					// 计时结束
					clearInterval(interval);
				} else {
					this.showCount = true;
					let time = endTime - nowTime;
					let day = parseInt(time / (60 * 60 * 24));
					let hour = parseInt((time % (60 * 60 * 24)) / 3600);
					let min = parseInt(((time % (60 * 60 * 24)) % 3600) / 60);
					let sec = parseInt(((time % (60 * 60 * 24)) % 3600) % 60);
					this.time = {
						day: this.timeFormat(day),
						hour: this.timeFormat(hour),
						min: this.timeFormat(min),
						sec: this.timeFormat(sec)
					};
				}
			}, 1000);
		}
	}
};
</script>

<style scoped lang="scss">
@import '../manghe.scss';
.goods-list {
	padding: 0;
	margin: 0;
}
</style>
